package me.zhengjie.config.utils;

import java.util.regex.Pattern;

public class FileNameGenerator {
    private static final String ILLEGAL_CHARACTERS_REGEX = "[/\\\\:*?\"<>|]"; // Windows非法字符
    private static final Pattern ILLEGAL_CHARACTERS_PATTERN = Pattern.compile(ILLEGAL_CHARACTERS_REGEX);

    public static String generateValidFileName(String baseName) {
        // 替换非法字符为下划线
        String sanitizedName = ILLEGAL_CHARACTERS_PATTERN.matcher(baseName).replaceAll("_");
        // 可选：限制长度
        if (sanitizedName.length() > 255) {
            sanitizedName = sanitizedName.substring(0, 254); // 保留最后一部分以避免截断单词
        }
        return sanitizedName;
    }

    public static void main(String[] args) {
        String baseName = "瞿菡倩（巴巴老师）";
        String validFileName = generateValidFileName(baseName);
        System.out.println("Valid File Name: " + validFileName);
    }
}